import java.util.ArrayList;
import java.util.List;


public class Graph {
	static List<Node> nodeList = new ArrayList<Node>();
	static int arrMatrix[][];
	static int x1Cor;
	static int x2Cor;
	static int y1Cor;
	static int y2Cor;
	static int res;
	static int xCorMain;
	static int yCorMain;
	
	/*
	 * Creates different cordinates so that they can be represented on the grid
	 */
	static void createLocations(int xAxis1, int xAxis2, int yAxis1, int yAxis2,
			int resolution) {
		x1Cor = xAxis1;
		x2Cor = xAxis2;
		y1Cor = yAxis1;
		y2Cor = yAxis2;
		res = resolution;
	}
	
	public static void addNode(Node node) {
		nodeList.add(node);
	}
	
	static void createGrid() {
		int xPoints = (x2Cor - x1Cor) / res;
		int yPoints = (y2Cor - y1Cor) / res;

		yCorMain = y1Cor;
		int nodeNumber = 0;
		Node corNode = new Node(xCorMain);

		for (int i = 0; i < yPoints; i++) {
			xCorMain = x1Cor;
			for (int j = 0; j < xPoints; j++) {
				corNode = new Node(nodeNumber);
				corNode.setXCor(xCorMain);
				corNode.setYCor(yCorMain);
				xCorMain = xCorMain + res;
				addNode(corNode);
				nodeNumber++;
			}
			yCorMain = yCorMain + res;
		}
	}
	
	static void createAdjMatrix() {
		arrMatrix = new int[nodeList.size()][nodeList.size()];
		int xCor = 0;
		int yCor = 0;
		for (int i = 0; i < nodeList.size(); i++) {
			int xCordinate = nodeList.get(i).xCor;
			int yCordinate = nodeList.get(i).yCor;

			for (int j = 0; j < nodeList.size(); j++) {

				xCor = nodeList.get(j).getXCor();
				yCor = nodeList.get(j).getYCor();

				if ((xCordinate == xCor && yCordinate == yCor)
						|| (xCordinate + 1 == xCor && yCordinate == yCor)
						|| (xCordinate == xCor && yCordinate + 1 == yCor)
						|| (xCordinate + 1 == xCor && yCordinate + 1 == yCor)) {
					arrMatrix[i][j] = 1;
				} else if ((xCordinate - 1 == xCor && yCordinate == yCor)
						|| (xCordinate - 1 == xCor && yCordinate + 1 == yCor)) {
					arrMatrix[i][j] = 1;
				} else if ((xCordinate == xCor && yCordinate - 1 == yCor)
						|| (xCordinate + 1 == xCor && yCordinate - 1 == yCor)) {
					arrMatrix[i][j] = 1;
				} else if ((xCordinate - 1 == xCor && yCordinate - 1 == yCor)
						|| (xCordinate - 1 == xCor && yCordinate + 1 == yCor)) {
					arrMatrix[i][j] = 1;
				}
			}
		}
	}
	
	static void removeAdjacencies(int nodeIndex) {

		for (int i = 0; i < arrMatrix[nodeIndex].length; i++) {
			arrMatrix[nodeIndex][i] = 0;
			arrMatrix[i][nodeIndex] = 0;
		}

	}
}
